package com.sunnada.demo.service.serviceimpl;

import com.sunnada.demo.bean.Dog;
import com.sunnada.demo.dao.DogRepository;
import com.sunnada.demo.log.service.TrackLogService;
import com.sunnada.demo.service.DogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @BelongsProject: mybatisproject2
 * @BelongsPackage: com.sunnada.demo.service.serviceimpl
 * @Author: 李瑞益
 * @CreateTime: 2018-10-08 09:10
 * @Description: mongodbService
 */
@Service
public class DogServiceImpl implements DogService {

    @Autowired
    private DogRepository dogRepository;

    @Override
    public void delete(String id) {
        Dog dog = new Dog();
        dog.setId(id);
        dogRepository.delete(dog);
    }

    @Override
    public Dog insert(Dog dog) {
        return dogRepository.insert(dog);
    }

    @Override
    public Dog update(Dog dog) {
        return dogRepository.save(dog);
    }

    @Override
    public Dog getById(String id) {
        Optional<Dog> user = dogRepository.findById(id);
        return user.orElse(null);
    }

    @Override
    public List<Dog> getList() {
        return dogRepository.findAll();
    }

    @Override
    public List<Dog> findByName(String name) {
        return dogRepository.findByName(name);
    }

    @Override
    public List<Dog> findByIdAndName(Object id, String name) {
        return dogRepository.findByIdAndName(id,name);
    }

    @Override
    public List<Dog> findByNameAndAge(String name, String age) {
        return null;
    }
}
